//
//  YXSerachServerTableViewCell.m
//  PYWGetColor
//
//  Created by 杜文杰 on 2018/6/25.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "YXSerachServerTableViewCell.h"
#import "StarView.h"

@interface YXSerachServerTableViewCell()
@property (nonatomic, strong) UILabel *titleLabel; // 标题
@property (nonatomic, strong) UILabel *orderDistanceLabel; // 距离
@property (nonatomic, strong) UILabel *customerAddressLabel; // 用户点评
@property (nonatomic, strong) UIImageView *userHeaderImageView; // 头像
@property (nonatomic, strong) StarView *starView; // 小星星
@property (nonatomic, strong) UILabel *commentNumLabel; // 评论数量
@end

@implementation YXSerachServerTableViewCell
- (void)setServerModellList:(ServerModellList *)serverModellList
{
    self.titleLabel.text = serverModellList.sitetitle;
    self.orderDistanceLabel.text = serverModellList.sitedesc;
    CGFloat starNum = [serverModellList.starnum floatValue];
    [_starView showMarkWithStar:starNum];
    NSLog(@"%.F",starNum);
    [self.userHeaderImageView sd_setImageWithURL:[NSURL URLWithString:serverModellList.photourl]];
    self.commentNumLabel.text = [NSString stringWithFormat:@"(%@)",serverModellList.commentnum];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.orderDistanceLabel];
        [self.contentView addSubview:self.customerAddressLabel];
        [self.contentView addSubview:self.starView];
        [self.contentView addSubview:self.commentNumLabel];
        UIView *lineView2 = [[UIView alloc]init];
        lineView2.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:lineView2];
        [self.contentView addSubview:self.userHeaderImageView];
        
        
        __weak typeof(self)weakself = self;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.mas_top).offset(10 / WIDTH_6S_SCALE);
            make.left.equalTo(weakself.mas_left).offset(20 / WIDTH_6S_SCALE);
            make.width.mas_equalTo(200 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        [self.orderDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.titleLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(weakself.titleLabel);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(200 / WIDTH_6S_SCALE);
        }];
        [self.customerAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.orderDistanceLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(weakself.titleLabel);
            //            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            //            make.width.mas_equalTo(230 / WIDTH_6S_SCALE);
        }];
        [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.customerAddressLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.right.left.equalTo(weakself);
            make.height.mas_equalTo(0.5);
        }];
        [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.customerAddressLabel.mas_centerY);
            make.left.equalTo(weakself.customerAddressLabel.mas_right).offset(5 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(15 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(60 / WIDTH_6S_SCALE);
        }];
        [self.commentNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.starView.mas_centerY);
            make.left.equalTo(weakself.starView.mas_right).offset(35 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(15 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(50 / WIDTH_6S_SCALE);
        }];
        
        [self.userHeaderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakself.mas_centerY);
            make.right.equalTo(weakself.mas_right).offset(-20 / WIDTH_6S_SCALE);
            make.width.mas_equalTo(60 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(60 / HEIGHT_6S_SCALE);
        }];
        self.userHeaderImageView.layer.cornerRadius = 5 / HEIGHT_6S_SCALE;
        self.userHeaderImageView.layer.masksToBounds = YES;
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.titleLabel.mas_top).offset(-10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(weakself);
            make.bottom.equalTo(lineView2.mas_bottom);
        }];
        
        
    }
    return self;
}
#pragma mark - init
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = getColor(blackColor);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = DEF_FontSize_16;
        [_titleLabel sizeToFit];
        _titleLabel.text = @"杜师傅（浑南长白苏家屯）";
    }
    return _titleLabel;
}
- (UILabel *)orderDistanceLabel{
    if (!_orderDistanceLabel) {
        _orderDistanceLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _orderDistanceLabel.backgroundColor = [UIColor clearColor];
        _orderDistanceLabel.textColor = getColor(blackColor);
        _orderDistanceLabel.textAlignment = NSTextAlignmentLeft;
        _orderDistanceLabel.numberOfLines = 0;
        _orderDistanceLabel.font = DEF_FontSize_14;
        [_orderDistanceLabel sizeToFit];
        _orderDistanceLabel.text = @"维修站点 . 500米";
    }
    return _orderDistanceLabel;
}
- (UILabel *)customerAddressLabel
{
    if (!_customerAddressLabel) {
        _customerAddressLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _customerAddressLabel.backgroundColor = [UIColor clearColor];
        _customerAddressLabel.textColor = getColor(textColor);
        _customerAddressLabel.textAlignment = NSTextAlignmentLeft;
        _customerAddressLabel.numberOfLines = 0;
        _customerAddressLabel.font = DEF_FontSize_14;
        [_customerAddressLabel sizeToFit];
        _customerAddressLabel.text = @"用户点评 ";
    }
    return _customerAddressLabel;
}
- (UILabel *)commentNumLabel
{
    if (!_commentNumLabel) {
        _commentNumLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _commentNumLabel.backgroundColor = [UIColor clearColor];
        _commentNumLabel.textColor = getColor(textColor);
        _commentNumLabel.textAlignment = NSTextAlignmentCenter;
        _commentNumLabel.numberOfLines = 0;
        _commentNumLabel.font = DEF_FontSize_14;
        [_commentNumLabel sizeToFit];
//        _commentNumLabel.text = @"(90) ";
    }
    return _commentNumLabel;
}
- (UIImageView *)userHeaderImageView
{
    if (!_userHeaderImageView) {
        _userHeaderImageView = [[UIImageView alloc]init];
        _userHeaderImageView.backgroundColor = [UIColor clearColor];
        _userHeaderImageView.image = [UIImage imageNamed:@"list_btn_pic.1"];
    }
    return _userHeaderImageView;
}
- (StarView *)starView{
    if(!_starView){
        
        _starView = [[StarView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.customerAddressLabel.frame) + 10 / WIDTH_6S_SCALE, self.customerAddressLabel.frame.origin.y, 100, 15)];
        [_starView showMarkWithStar:4];
    }
    return _starView;
}
@end



